//
//  HomeBindVC.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/24.
//

#import "HomeBindVC.h"
#import "HomeSascanVC.h"
#import "HomeJoinVC.h"

@interface HomeBindVC ()<HomeSascanVCDelegate>
@property (nonatomic,strong) UILabel * infoLabel;
@property (nonatomic,strong) UIImageView * iconView;
@property (nonatomic,strong) UIButton * enterBtn;

@property (nonatomic,strong) HomeTipsView * tipsView;
@property (nonatomic,strong) NSString * code;
@end

@implementation HomeBindVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSubViewLayout];
}

-(void)setSubViewLayout{
    
    self.title = @"激活您的戒指";
    self.navgationView.infoLabel.textColor = RDRGB(0x714933);
    
    [self.view addSubview:self.infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(320 * FMScaleX, 60 * FMScaleX));
        make.centerX.equalTo(@0);
        make.top.mas_offset(NavHeight + 20 * FMScaleX);
    }];
    [self.view addSubview:self.iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(150 * FMScaleX, 150 * FMScaleX));
        make.center.equalTo(@0);
    }];
    [self.view addSubview:self.enterBtn];
    [_enterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(330 * FMScaleX, 50 * FMScaleX));
        make.centerX.equalTo(@0);
        make.bottom.mas_offset(-kSafeAreaHeight - 50 * FMScaleX);
    }];
}

-(void)enterBtnAction{
    
    HomeSascanVC * sanVC = [[HomeSascanVC alloc]init];
    sanVC.delegate = self;
    [self.navigationController pushViewController:sanVC animated:YES];
    
}

-(void)requestCodeWith:(NSString *)code{
    
    [self.tipsView startAnimationWithTitle:@"提示" info:@"是否激活设备？"];
    @WeakObj(self)
    _tipsView.enterdBtnBlock = ^{
        @StrongObj(self)
        FhudShowStr(@"激活成功");
        HomeJoinVC * vc = [[HomeJoinVC alloc]init];
        vc.macStr = code;
        vc.isFirstType = 1;
        [self.navigationController pushViewController:vc animated:YES];
    };
}

-(UILabel *)infoLabel{
    
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc]init];
        _infoLabel.font = Regular(14 * FMScaleX);
        _infoLabel.textColor = RDRGB(0x714933);
        _infoLabel.numberOfLines = 0;
        _infoLabel.text = @"戒指在出厂时已设置为出厂休眠状态，在连接APP前请务必充电并扫描二维码（包装盒背面右下角二维码）激活戒指，绑定激活后才能获得全部权益,确保戒指蓝牙已开启。";
    }
    return _infoLabel;
}
-(UIImageView *)iconView{
    
    if (!_iconView) {
        _iconView = [[UIImageView alloc]init];
        _iconView.image = [UIImage imageNamed:@"Home_jiezhi_icon"];
    }
    return _iconView;
}
-(UIButton *)enterBtn{
    
    if (!_enterBtn) {
        _enterBtn = [[UIButton alloc]init];
        [_enterBtn setBackgroundImage:[UIImage imageNamed:@"Common_btn_bg"] forState:UIControlStateNormal];
        [_enterBtn setTitle:@"扫码激活设备" forState:UIControlStateNormal];
        [_enterBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [_enterBtn addTarget:self action:@selector(enterBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _enterBtn;
}

-(HomeTipsView *)tipsView{
    
    if (!_tipsView) {
        _tipsView = [[HomeTipsView alloc]initWithFrame:self.view.bounds];
        [self.view addSubview:_tipsView];
    }
    return _tipsView;
}
@end
